package io;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲输出流写出数据的缓冲区问题
 */
public class FlushDemo {
    public static void main(String[] args) throws IOException {

        /*FileOutputStream fos = new FileOutputStream("./test.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        String str = "斑马斑马你不要睡着了，让我看看你的尾巴";
        byte[] data = str.getBytes(StandardCharsets.UTF_8);
        bos.write(data);
        bos.flush();
        bos.close();
        System.out.println("文件写入完毕");*/
        FileOutputStream fos = new FileOutputStream("./fos.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        String str = "斑马斑马你不要睡着了，让我看看你的尾巴";
        byte[] data = str.getBytes(StandardCharsets.UTF_8);
        bos.write(data);
        bos.flush();
        bos.close();
        System.out.println("文件写入完毕");
    }
}
